package demo02_lock;

/**
 * @author kunkun
 * @className TicketProblem
 * @Description 买票问题
 * @date 2025/3/5 16:11
 */
public class TicketProblem_basic {

    public static void main(String[] args) {
        new Thread(new ticket(),"A").start();
        new Thread(new ticket(),"B").start();
        new Thread(new ticket(),"C").start();
    }


    static class ticket implements Runnable{

        private int ticketsNum=20;

        public void sail(){
            System.out.println("购买第"+ticketsNum+"张票，剩余"+(ticketsNum--)+"张票");
        }

        public void run() {
            while(ticketsNum>0){
                sail();
            }
        }
    }

}

